import 'package:flutter/material.dart';
import 'package:flutter_deer/game/models/game_item_entity.dart';
import 'package:flutter_deer/index/models/com_code_entity.dart';
import 'package:flutter_deer/index/models/expenditure_progress_entity.dart';
import 'package:flutter_deer/widgets/state_layout.dart';

class ExpenditureProgressListPageProvider extends ChangeNotifier {
  ExpenditureProgressPageEntity? _itemPage;
  List<ExpenditureProgressEntity>? _list = [];
  StateType? _stateType = StateType.loading;
  int? _currentPage = 1;
  List<CodeMapEntity>? _fundTypeCodeList = [];
  List<CodeMapEntity>? _depBgtEcoCodeList = [];
  List<CodeMapEntity>? _govBgtEcoCodeList = [];
  List<CodeMapEntity>? _expFuncCodeList = [];
  List<CodeMapEntity>? get depBgtEcocodeList => _depBgtEcoCodeList;
  List<CodeMapEntity>? get fundTypeCodeList => _fundTypeCodeList;
  List<CodeMapEntity>? get govBgtEcocodeList => _govBgtEcoCodeList;
  List<CodeMapEntity>? get expFunccodeList => _expFuncCodeList;
  ExpenditureProgressPageEntity? get itemPage => _itemPage;
  int? get total => _itemPage!.total;
  int? get current => _itemPage!.current;
  List<ExpenditureProgressEntity>? get records => _itemPage!.records;
  List<ExpenditureProgressEntity>? get list => _list;
  bool? get hasMore => _itemPage!.current! < _itemPage!.pages!;
  StateType? get stateType => _stateType;
  int? get currentPage => _currentPage;

  void setExpenditureProgressItemPage(ExpenditureProgressPageEntity? pageEntity) {
    print('setExpenditureProgressItemPage');
    this._itemPage = pageEntity;
    print('aaaaaa');
    this._currentPage = pageEntity!.current;
    print(_currentPage.toString());
    if (pageEntity.current == 1) {
      this._list = pageEntity!.records;
    } else {
      for (int i = 0; i < pageEntity.records!.length; i++) {
        ExpenditureProgressEntity item = pageEntity.records!.elementAt(i);
        this._list!.add(item);
      }
    }
    print(this._list!.length.toString() + '');
    this._stateType = StateType.game;
    notifyListeners();
  }

  void setCodeMap(List<CodeMapEntity>? fundType) {
    this._fundTypeCodeList = fundType;
    print(fundType);
    notifyListeners();
  }

  void setDepBgtEcoCodeMap(List<CodeMapEntity>? fundType) {
    this._depBgtEcoCodeList = fundType;
    print(fundType);
    notifyListeners();
  }

  void setGovBgtEcoCodeMap(List<CodeMapEntity>? fundType) {
    this._govBgtEcoCodeList = fundType;
    print(fundType);
    notifyListeners();
  }

  void setExpFuncCodeMap(List<CodeMapEntity>? fundType) {
    this._expFuncCodeList = fundType;
    print(fundType);
    notifyListeners();
  }
}
